import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;

public class _09_ListOfProductsClass {

	public static void main(String[] args) throws IOException {

		Locale.setDefault(Locale.ROOT);

		ArrayList<_09_Product> productsList = new ArrayList<_09_Product>();

		try {

			BufferedReader inputBufferStream =
					new BufferedReader(new FileReader("Input products.txt"));
			Writer outputBufferStream =
					new BufferedWriter(new FileWriter("Pricely sorted products.txt"));

			String line = null;

			while ((line = inputBufferStream.readLine()) != null) {

				String[] productAndPriceSplitted = line.split(" ");
				productsList.add(new _09_Product(productAndPriceSplitted[0],
						Double.parseDouble(productAndPriceSplitted[1])));
			}

			Collections.sort(productsList);

			NumberFormat formattingSample = new DecimalFormat("0.00");

			for (_09_Product product : productsList) {

				outputBufferStream.write(formattingSample.format(product.getPrice()) +
						" " + product.getName() + "\n" );
			}

			outputBufferStream.close();
		}
		catch (Exception e) {

			System.out.println("Error: " + e.getMessage());
		}
		finally {

			System.out.println("Operation completed");
		}
	}
}